package com.mdoya.controller;

import com.mdoya.domain.Orders;
import com.mdoya.query.BaseQuery;
import com.mdoya.response.ResultResponse;
import com.mdoya.service.OrderService;
import com.mdoya.utils.ThreadLocalContextUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author mdoya
 * @version 1.0
 * @description:
 */
@Slf4j
@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     *  提交订单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public ResultResponse add(@RequestBody Orders orders){
        log.info("加入购物车: {}",orders);

        return ResultResponse.success(orderService.add(orders) > 0 ? "提交订单成功" : "提交订单失败");
    }

    /**
     *  后台订单查询分页
     * @param baseQuery 分页参数
     * @return
     */
    @GetMapping("/page")
    public ResultResponse selectPage(BaseQuery baseQuery){
        log.info("后台订单分页: {}",baseQuery);
        return ResultResponse.success(orderService.selectPage(baseQuery));
    }

    /**
     *  前端订单查询分页
     * @param baseQuery
     * @return
     */
    @GetMapping("/userPage")
    public ResultResponse selectPageIndex(BaseQuery baseQuery){
        log.info("前端最新订单: {}",baseQuery);
        baseQuery.setUserId(ThreadLocalContextUtils.getUserLongId());
        return ResultResponse.success(orderService.selectPageIndex(baseQuery));
    }
}
